﻿using GraphSharp.Controls;
using XmlStudio.DataLayer;
using System.ComponentModel;
using System.Windows;

namespace XmlStudio.ViewModel.Node {
    public abstract class XmlNodeViewModel : INotifyPropertyChanged {
        private VertexControl vertexControl;

        public string Id {
            get;
            private set;
        }

        public BigXmlNode Node {
            get;
            private set;
        }

        protected XmlNodeViewModel() {

        }

        protected XmlNodeViewModel(string id, BigXmlNode node, IInputElement commandTarget) {
            this.Id = id;
            this.Node = node;
            this.CommandTarget = commandTarget;
        }

        public abstract void Refresh();

        public VertexControl VertexControl {
            get { return this.vertexControl; }
            set {
                this.vertexControl = value;
                this.OnPropertyChanged("VertexControl");
            }
        }

        public IInputElement CommandTarget { get; private set; }

        private void OnPropertyChanged(string propertyName) {
            var propertyChanged = this.PropertyChanged;
            if(propertyChanged != null) {
                propertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}